package edu.bit.water.controller;

import edu.bit.water.entity.*;
import edu.bit.water.service.WasteWaterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/waste_water")
public class WasteWaterController {

    @Autowired
    private WasteWaterService wasteWaterService;

    @RequestMapping("/table1_select")
    @ResponseBody
    public List<WasteWaterTable1> table1Select(int lastId) {
        return wasteWaterService.table1Select(lastId);
    }

    @RequestMapping("/table2_select")
    @ResponseBody
    public List<WasteWaterTable2> table2Select(int lastId) {
//        System.out.println("lastId = " + lastId);
        return wasteWaterService.table2Select(lastId);
    }

    @RequestMapping("/get_meta_data")
    @ResponseBody
    public List<MetaBaseline> getMetaData(String stdNumber) {
        return wasteWaterService.getMetaData(stdNumber);
    }

    @RequestMapping("/get_table2_data")
    @ResponseBody
    public List<WasteWaterTable2> getTable2Data(String lastId) {
        return wasteWaterService.getTable2Data(lastId);
    }

    @RequestMapping("/get_table1_data")
    @ResponseBody
    public List<WasteWaterTable1> getTable1Data(String lastId) {
        return wasteWaterService.getTable1Data(lastId);
    }

    @RequestMapping("/table1Insert")
    @ResponseBody

    public void table1Insert(WasteWaterTable1 wasteWaterTable1)
    {
        wasteWaterService.table1Insert(wasteWaterTable1);
    }

    @RequestMapping("/table2Insert")
    @ResponseBody

    public void table2Insert(WasteWaterTable2 wasteWaterTable2)
    {
        wasteWaterService.table2Insert(wasteWaterTable2);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public void delete(@RequestBody List<Integer> ids) {
//        for (int id: ids) {
//            System.out.println(id);
//        }
        wasteWaterService.delete(ids);
    }

    @RequestMapping("/table1update")
    @ResponseBody
    public void table1update(WasteWaterTable1 wasteWaterTable1) {
        wasteWaterService.table1update(wasteWaterTable1);
    }

    @RequestMapping("/table2update")
    @ResponseBody
    public void table2update(WasteWaterTable2 wasteWaterTable2) {
        wasteWaterService.table2update(wasteWaterTable2);
    }


    @RequestMapping("/label_update")
    @ResponseBody
    public Map<String, String> labelUpdate(WasteWaterEva wasteWaterEva){
        return wasteWaterService.labelUpdate(wasteWaterEva);
    }


}
